<template>
  <section>
    <el-button size="mini" type="text" @click="finishReportBtn">完成报告</el-button>
    <el-row>
      <el-autocomplete
        v-model="selText"
        size="small"
        :fetch-suggestions="querySearchAsync"
        placeholder="输入姓名"
        value-key="name"
        @select="handleSelect"></el-autocomplete>
    </el-row>
    <el-row>
      <el-table v-if="issueJobs" :data="issueJobs.content">
        <el-table-column></el-table-column>
      </el-table>
    </el-row>
  </section>
</template>

<script>
  import {mapGetters, mapActions, mapMutations} from 'vuex'
  import errHandler from '@/assets/errHandler.js'
  export default {
    name: 'issue-report',
    data() {
      return {
        selText:'',
        selCustomer:null,
        timeoutHandle:null,
        issueJobs:null,

      }
    },
    computed:{
      ...mapGetters(['department'])
    },
    created(){
      console.log('报告页面')
      this.loadJobs(0)
    },
    methods:{
      ...mapActions({
        fetch: 'fetch'
      }),
      querySearchAsync(qs,cb){
        //console.log(qs)
        if(!qs){
          cb([])
          return
        }
        clearTimeout(this.timeoutHandle)
        this.timeoutHandle = setTimeout(()=>{
          this.fetch({name:'getUserList',data:{keywords:qs}})
            .then(res=>{
              console.log(res)
              cb(res.content)
            }).catch(err=>{
              console.log(err)
              errHandler.handle(this,err)
          })
        },1000)
      },
      handleSelect(item){
        this.selCustomer=item
        // console.log(item,this.selUser)
        console.log(this.selCustomer)
      },
      loadJobs(page){
        console.log(this.department)
        if(!this.department) return
        let data={page,departmentId:this.department.id}
        this.fetch({name:"listJobs",data}).then(res=>{
          console.log(res)
          this.issueJobs = res
        }).catch(err=>{
          console.log(err)
          errHandler.handle(this,err)
        })
      }
    }
  }
</script>

<style lang="scss">

</style>
